Skip to content

Conversation

@hd9568
Copy link
Contributor

@hd9568 hd9568 commented Oct 17, 2025

No description provided.

@paddle-bot
Copy link

paddle-bot bot commented Oct 17, 2025

感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-7556.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html
预览工具的更多说明,请参考:飞桨文档预览工具

Copy link
Collaborator

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还有2个地方需要改下,提升可读性:

  1. 第3列把映射分类都拷贝过来
infoflow 2025-10-17 11-40-54

避免用户搜索某个API,却只能去表格标头里找分类。提升可读性。

  1. 这里的文字说明省略点
infoflow 2025-10-17 11-45-18

if ! download_file "${BACKUP_API_ALIAS_MAPPING_URL}" "${TOOLS_DIR}/api_alias_mapping.json"; then
echo "ERROR: API alias mapping download failed (both main and backup URLs). Exiting."
echo "INFO: API alias mapping download failed. Checking for cached file..."
if check_cached_file; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的逻辑需要优化一下,如果有1个没下载成功。则复制cache,同时后面也不需要再下载文件,也不需要再跑 api_alias_mapping判断、get_api_difference_info、generate_pytorch_api_mapping这些冗余逻辑。

也就是要么走 自动生成generate_pytorch_api_mapping整体的逻辑、要么复制cache。两者二选一。

@@ -0,0 +1,375 @@
import argparse
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以使用generate_api_difference来刷新一下目前已有的 api_difference,第2类目录里面的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改,后续generate_api_difference没问题了会加到CI里

Copy link
Collaborator

@zhwesky2010 zhwesky2010 Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改,后续generate_api_difference没问题了会加到CI里

这个本地自动化处理就可以。不用在CI里处理。

@github-actions
Copy link

github-actions bot commented Oct 17, 2025

📚 本次 PR 文档预览链接(点击展开)
ℹ️ 预览提醒
请等待 Docs-NEW 流水线运行完成后再点击预览链接,否则可能会看到旧版本内容或遇到链接无法访问的情况。
  • docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md: 点击预览

echo "ERROR: API alias mapping download failed (both main and backup URLs). Exiting."
echo "INFO: API alias mapping download failed. Checking for cached file..."
if check_cached_file; then
if ! copy_cached_file; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果copy_cached_file了,那么就不用继续下载其他的文件,也不用跑下面的get_api_difference_info、generate_pytorch_api_mapping这些逻辑。直接就结束了。

@@ -29,8 +29,7 @@
### 1. API 完全一致
**分类简介**
Copy link
Collaborator

@zhwesky2010 zhwesky2010 Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这么写:

简介此类 API 没有转写成本,两者用法完全一致, 只需将代码中所有torch前缀替换为 paddle即可。(也可只在文件最上方插入一行 import paddle as torch)。示例如下。

# PyTorch 写法
torch.eye(5)
torch.einsum('ii->i', x)
torch.nn.Softplus(beta=0.5, threshold=15)

# Paddle 写法
paddle.eye(5)                                 #仅替换torch前缀
paddle.einsum('ii->i', x)                     #仅替换torch前缀
paddle.nn.Softplus(beta=0.5, threshold=15)    #仅替换torch前缀

| 序号 | Pytorch 最新 release | Paddle develop | 备注 |
|------|-------------------|---------------|------|
| 序号 | Pytorch 最新 release | Paddle develop | 映射分类 | 备注 |
|------|-------------------|---------------|----------|------|

### 2. 仅 API 调用方式不一致
**分类简介**
Copy link
Collaborator

@zhwesky2010 zhwesky2010 Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

简介:此类 API 的转写成本较低,只需对 API 调用方式进行改写,无需转写 API 参数部分。示例如下。

# PyTorch 写法给几个例子# Paddle 写法给个例子# 仅API名称不同给个例子# 仅API路径不同给个例子# Tensor类方法改普通方法给个例子# Tensor类方法改属性给个例子# Tensor类属性改方法

@zhwesky2010
Copy link
Collaborator

zhwesky2010 commented Oct 17, 2025

前面这个也保持同步

infoflow 2025-10-17 15-01-31


```python
# PyTorch 写法
torch.numel(x)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成这种写法吧,更直观一点,后面用 #号 注释下,表明干了什么,例如Tensor方法转属性。第1类也这么写。

torch.numel(x) -> x.size
x.matrix_exp() -> paddle.linalg.matrix_exp(x)
x.to_sparse(1) -> x.to_sparse_coo(1)

}

# Download API alias mapping file
echo "INFO: Downloading API alias mapping file"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

简化下写法,这5个下载逻辑,以及handle_download_failure逻辑,可以都统一合download_file。

download_file调用5行,每次传入一个文件即可。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

```python
# PyTorch 写法 -> Paddle 写法
torch.numel(x) -> x.size # Tensor 方法转属性
out = x.matrix_exp() -> paddle.linalg.matrix_exp(x) # 函数转方法
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

下个pr可以把out去掉

@zhwesky2010 zhwesky2010 merged commit a856f38 into PaddlePaddle:develop Oct 17, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants